<template>
	<view class="xiaoxi">
		<view class="mainpadding">
			<view class="flexcenter placeimage" v-show="!list.total">
				<image src="../../static/image/system/zwxx.png" mode=""></image>
			</view>
			<view class="margin_top" v-for="(item,index) in list.data" :key="index" @click="tzxq(item)">
				<view class="flexbetween">
					<view class="flexleft">
						<view class="touxiang margin_right2">
							<image :src="item.user.avatar" mode=""></image>
						</view>
						<view class="titletext youbianju">{{item.user.nickname}}</view>
					</view>
					<view class="nostrongtext">{{item.createtime | formatDate('-')}}</view>
				</view>
				<view class="titletext dayoubianku">{{item.content}}</view>
				<view class="tiaba dayoubianku" v-if="item.pforum_comment != null">{{item['pforum_comment']['content']}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		// onLoad(options) {
		// 	let token = options.token
		// 	uni.setStorageSync('token', token);
		// },
		onShow() {
			// 如果用户未登录点击去登陆
			// if (!httpRequest.checkIsLogin()) {
			// 	httpRequest.doLogin();
			// 	return false;
			// }
			let is_login = httpRequest.checkIsLogin();
			if (is_login) {
				this.init()
			}
		},
		filters: {
			// 时间戳处理
			formatDate: function(value, spe = '/') {
				let maohao=':'
				value = value * 1000
				let data = new Date(value);
				let year = data.getFullYear();
				let month = data.getMonth() + 1;
				let day = data.getDate();
				let h = data.getHours();
				let mm = data.getMinutes();
				let s = data.getSeconds();
				month = month >= 10 ? month : "0" + month;
				day = day >= 10 ? day : "0" + day;
				h = h >= 10 ? h : "0" + h;
				mm = mm >= 10 ? mm : "0" + mm;
				s = s >= 10 ? s : "0" + s;
				return `${month}${spe}${day}  ${h}${maohao}${mm}`;
			}
		},
		methods: {
			//消息列表
			init(isPage, page) {
				let _this = this;
				httpRequest.request('forum_comment/message', 'POST', {
					page: page || 1,
					limit: _this.limit,
					// school_id:_this.school_id
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let arr = []
						res.data.data.forEach(item=>{
							if(item.content){
								arr.push(item)
							}
						})
						_this.list.data = arr;
						console.log(_this.list.data)
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(arr);
						} else {
							console.log(res,56);
							_this.list = resList
							_this.list.data = arr;
						}
						console.log(_this.list.data,888)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// 跳转详情
			tzxq(item) {
				let msg = {
					detailid:item.forum_id,//列表id
					plid:item.pforum_comment?item.pforum_comment.id:1//评论id
				}
				uni.navigateTo({
					url: '/pages/jishi/xiangqingsj?idjpp=' + encodeURIComponent(JSON.stringify(msg))
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tiaba {
		width: 78%;
		background: #F6F6F6;
		border-radius: 20rpx;
		padding: 15rpx 0 15rpx 30rpx;
		font-size: 24rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #999999;
	}

	.dayoubianku {
		margin: 20rpx 0 0 120rpx;
	}

	.youbianju {
		margin-left: 10rpx;
	}

	.touxiang {
		width: 99rpx;
		height: 99rpx;
		border-radius: 50%;

		image {
			border-radius: 50%;
			width: 100%;
			height: 100%;
		}
	}
</style>
